# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter


class Scrapy05MoviePipeline:
    def open_spider(self,spider):
        self.file=open('movie.json','w',encoding='utf-8')

    def process_item(self, item, spider):
        self.file.write(str(item))
        return item

    def close_spider(self,spider):
        self.file.close()



import urllib.request
#开启多天管道下载电影图片
class MoviePicDownload:
    def process_item(self,item,spider):
        url=item.get('pic_url')

        #自己新建一个文件
        filename='./moviePic/'+item.get('name')+'.jpg'
        urllib.request.urlretrieve(url=url,filename=filename)
        return item